/* Turska UI library
 * Copyright 2003-2008 Jetro Lauha
 * All rights reserved.
 * Web: http://iki.fi/jetro/ or http://jet.ro
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of EITHER:
 *   (1) The GNU Lesser General Public License as published by the Free
 *       Software Foundation; either version 2.1 of the License, or (at
 *       your option) any later version. The text of the GNU Lesser
 *       General Public License is included with this library in the
 *       file LICENSE-LGPL.txt.
 *   (2) The BSD-style license that is included with this library in
 *       the file LICENSE-BSD.txt.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
 * LICENSE-LGPL.txt and LICENSE-BSD.txt for more details.
 *
 * $Id: UIImageOpenGL.h,v 1.4 2008/03/27 11:44:24 tonic Exp $
 * $Revision: 1.4 $
 */

#ifndef UIIMAGEOPENGL_H_INCLUDED
#define UIIMAGEOPENGL_H_INCLUDED


//! OpenGL implementation of the UIImage interface.
/*! \note In this implementation the COLOR flag is always assumed to be
 *        enabled, and it is also set enabled on initialization.
 */
class UIImageOpenGL : public UIImage
{
public:

    //! Constructs a new OpenGL UI image to a default state.
    /*! \param width width of the image.
     *  \param height height of the image.
     *  \param glId OpenGL name id for the loaded texture image.
     *  \param uv array of 4 FLOATs describing the top-left and bottom-right u,v coordinates.
     */
    UIImageOpenGL(UINT32 width, UINT32 height, UINT32 flags, UINT glId, const FLOAT *uv);
    //! Destructor deletes the texture.
    virtual ~UIImageOpenGL();

    // From UIImage:

    virtual void setColor(UINT8 red, UINT8 green, UINT8 blue, UINT8 alpha = 0xff);
    inline virtual void setColor(FLOAT red, FLOAT green, FLOAT blue, FLOAT alpha = 1.0f)
    {
        mColor[0] = red;
        mColor[1] = green;
        mColor[2] = blue;
        mColor[3] = alpha;
    }

    virtual void setTargetSize(UINT32 width, UINT32 height) { setTargetSize((FLOAT)width, (FLOAT)height); }
    virtual void setTargetSize(FLOAT width, FLOAT height) { mTargetWidth = width; mTargetHeight = height; }

    virtual void setAngle(FLOAT angle) { mAngle = angle; }

    virtual void setScale(FLOAT scale) { mScaleX = mScaleY = scale; }
    virtual void setScale(FLOAT scaleX, FLOAT scaleY) { mScaleX = scaleX; mScaleY = scaleY; }
    virtual void setPivot(FLOAT centerX, FLOAT centerY) { mPivotX = centerX + mNegHalfWidth; mPivotY = centerY + mNegHalfHeight; }

    virtual void draw(INT32 x, INT32 y) { draw((FLOAT)x, (FLOAT)y); }
    virtual void draw(FLOAT x, FLOAT y) { draw(mDrawMode, mFlags, x, y); }

    virtual void draw(UINT drawMode, UINT32 flags, INT32 x, INT32 y) { draw(drawMode, flags, (FLOAT)x, (FLOAT)y); }
    virtual void draw(UINT drawMode, UINT32 flags, FLOAT x, FLOAT y) { draw(drawMode, flags, x, y, mColor); }

    virtual void draw(UINT drawMode, UINT32 flags, FLOAT x, FLOAT y, FLOAT red, FLOAT green, FLOAT blue, FLOAT alpha);

    virtual void draw(UINT drawMode, UINT32 flags, FLOAT x, FLOAT y, const FLOAT *color);

    // UIImageOpenGL additions:

    inline UINT getGLId() const { return mGLId; }
    inline FLOAT * getUV() { return mUV; }

protected:

    UINT mGLId;
    FLOAT mUV[4];
    const FLOAT mNegHalfWidth;
    const FLOAT mNegHalfHeight;
    const FLOAT mPosHalfWidth;
    const FLOAT mPosHalfHeight;
    FLOAT mColor[4];
    FLOAT mTargetWidth;
    FLOAT mTargetHeight;
    FLOAT mAngle;
    FLOAT mScaleX, mScaleY;
    FLOAT mPivotX, mPivotY;
};


#endif // !UIIMAGEOPENGL_H_INCLUDED
